package com.woniuxy.closer.controller;


import com.woniuxy.closer.ResponseEntity;
import com.woniuxy.closer.entity.DetectionRegistration;
import com.woniuxy.closer.service.DetectionRegistrationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 李玉桃
 * @since 2022-07-20
 */
@RestController
@RequestMapping("/closer/detection-registration")
public class DetectionRegistrationController {

    @Autowired
    DetectionRegistrationService detectionRegistrationService;

    @GetMapping("{id}")
    public ResponseEntity findById(@PathVariable int id){
        return new ResponseEntity(detectionRegistrationService.getById(id));
    }

    @PostMapping("")
    public ResponseEntity save(@RequestBody DetectionRegistration detectionRegistration){
        boolean flag = detectionRegistrationService.save(detectionRegistration);
        if(flag){
            return ResponseEntity.SUCCESS;
        }else{
            return ResponseEntity.ERROR;
        }
    }

    @DeleteMapping("")
    public ResponseEntity delete(@PathVariable int id) {
        boolean flag = detectionRegistrationService.removeById(id);
        if (flag) {
            return ResponseEntity.SUCCESS;
        } else {
            return ResponseEntity.ERROR;
        }
    }

    @PostMapping("find")
    public ResponseEntity findByCondition(@RequestBody Map map){
        return new ResponseEntity(detectionRegistrationService.listByMap(map));
    }

}

